home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / programs / documentation / lightwave / sdk / sample / testcmd / testcmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-05  |  2.4 KB  |  106 lines

  1. /*
  2.  * TESTCMD.C -- Modeler Plugin Command
  3.  *        Test requesters and messages
  4.  *
  5.  * written by Stuart Ferguson
  6.  * last revision  12/6/94
  7.  */
  8. #include <splug.h>
  9. #include <lwmod.h>
  10. #include <stdio.h>
  11.  
  12.  
  13.     XCALL_(int)
  14. Activate (
  15.     long             version,
  16.     GlobalFunc        *global,
  17.     ModCommand        *local,
  18.     void            *serverData)
  19. {
  20.     MessageFuncs        *message;
  21.     StateQueryFuncs        *query;
  22.     DynaReqFuncs        *request;
  23.     DynaRequestID         dr;
  24.     DyReqControlDesc     desc;
  25.     DynaValue         val;
  26.     const char        *ohShit;
  27.     char            *strings[4], *items[4];
  28.     char             t1[40], t2[40], t3[40];
  29.     int             c1, c2, ok;
  30.  
  31.     XCALL_INIT;
  32.     if (version != 1)
  33.         return AFUNC_BADVERSION;
  34.  
  35.     message = (*global) ("Info Messages", GFUSE_TRANSIENT);
  36.     query   = (*global) ("LWM: State Query", GFUSE_TRANSIENT);
  37.     request = (*global) ("LWM: Dynamic Request", GFUSE_TRANSIENT);
  38.     if (!message || !query || !request)
  39.         return AFUNC_BADGLOBAL;
  40.  
  41.     (*message->warning) ("Hello from TEST COMMAND", "I bring you a warning.");
  42.     (*message->error) ("This would be an error, were not a test.", NULL);
  43.  
  44.     dr = (*request->create) ("Testing, Testing...");
  45.     if (!dr) {
  46.         ohShit = "Could not create requester.";
  47.         goto fail1;
  48.     }
  49.  
  50.     ohShit = "Cound not add control.";
  51.  
  52.     desc.type = DY_TEXT;
  53.     desc.text.text = strings;
  54.     sprintf (t1, "Layers - active:%d  bg:%d",
  55.                 (*query->layerMask) (OPLYR_FG),
  56.                 (*query->layerMask) (OPLYR_BG));
  57.     sprintf (t2, "Current Surface: %s",
  58.                 (*query->surface) ());
  59.     sprintf (t3, "Number of points: %d",
  60.                 (*query->bbox) (OPLYR_FG, NULL));
  61.     strings[0] = t1;
  62.     strings[1] = t2;
  63.     strings[2] = t3;
  64.     strings[3] = NULL;
  65.     c1 = (*request->addCtrl) (dr, "Hello", &desc);
  66.     if (c1 < 0)
  67.         goto fail2;
  68.  
  69.     desc.type = DY_CHOICE;
  70.     desc.choice.vertical = 0;
  71.     desc.choice.items = items;
  72.     items[0] = "Choice 1";
  73.     items[1] = "X";
  74.     items[2] = "Foo and Blah";
  75.     items[3] = NULL;
  76.     c2 = (*request->addCtrl) (dr, "What Next?", &desc);
  77.     if (c2 < 0)
  78.         goto fail2;
  79.  
  80.     val.type = DY_INTEGER;
  81.     val.intv.value = 1;
  82.     (*request->valueSet) (dr, c2, &val);
  83.     ok = (*request->post) (dr);
  84.     (*request->valueGet) (dr, c2, &val);
  85.     (*request->destroy) (dr);
  86.  
  87.     if (ok) {
  88.         sprintf (t1, "Choice was %d.", val.intv.value);
  89.         (*message->info) ("Requester was OKed;", t1);
  90.     }
  91.     return AFUNC_OK;
  92.  
  93. fail2:
  94.     (*request->destroy) (dr);
  95. fail1:
  96.     (*message->error) (ohShit, NULL);
  97.     return AFUNC_OK;
  98. }
  99.  
  100.  
  101. /*
  102.  * Globals necessary to declare the class and name of this plugin server.
  103.  */
  104. char        ServerClass[] = "CommandSequence";
  105. char        ServerName[]  = "Demo_TestCommand";
  106.